package com.zhangxujie.litewords.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.RawQuery;
import androidx.room.Update;
import androidx.sqlite.db.SupportSQLiteQuery;

import com.zhangxujie.litewords.entity.Words;

import java.util.ArrayList;
import java.util.List;

@Dao
public interface WordsDAO {

    @Query("SELECT * FROM words")
    List<Words> getAll();

    @Query("SELECT * FROM words ORDER BY RANDOM() LIMIT 10")
    List<Words> loadRandom10Words();

    @Query("SELECT * FROM words ORDER BY RANDOM() LIMIT :n")
    List<Words> loadRandomNWords(int n);

    @Query("SELECT * FROM words WHERE word=:word")
    Words queryByWord(String word);

    @Insert
    void insertAll(Words... words);

    @Delete
    void delete(Words words);

    @Update
    void update(Words word);

    @RawQuery
    Object rawSql(SupportSQLiteQuery query);

}
